/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {void} Do not return anything, modify head in-place instead.
 */
export var reorderList = function (head) {
  const nodes = []
  let node = head
  while (node.next) {
    nodes.push(node.next)
    node = node.next
  }
  let curr = head
  let isPop = true
  while (nodes.length > 0) {
    curr.next = isPop ? nodes.pop() : nodes.shift()
    isPop = !isPop
    curr = curr.next
  }
  curr.next = null
}
